package frontend.parser.syntaxtree;

import frontend.lexer.TKType;
import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

/**
 * funFParam 形参结点
 *
 * @author 杨凯伟
 * @date 2024/10/14
 */
public class FuncFParamsNode extends SyntaxNode {
    public List<FuncFParamNode> params = new ArrayList<>();//FuncFParam

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        Iterator<FuncFParamNode> iterator = params.iterator();
        if (iterator.hasNext()) {//对于第一个
            iterator.next().walk(terConsumer, nonTerConsumer);
        }
        iterator.forEachRemaining(constDef -> {//对于剩下的
            terConsumer.accept(new TerminalSymbol(TKType.COMMA));
            constDef.walk(terConsumer, nonTerConsumer);
        });
        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }

    @Override
    public String getType() {
        return "FuncFParams";
    }
}
